// pages/radar/to-vip.js
const share = require('../../utils/share.js')

const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        index: 0
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        share(options)

        this.loadData()
    },
    toHow(){
        wx.navigateTo({
            url: '/pages/mine/partner/make-money',
        })
    },
    loadData() {
        wx.showLoading({
            title: '加载中...',
        })
        app.http.get('city/tiny-station/get-price').then(res => {
            res.data[0].checked = true
            this.setData({
                list: res.data,
            })
            wx.hideLoading()
        })
    },
    radioChange(e) {
        var index = +e.detail.value
        this.setData({
            index
        })
    },
    pay() {
        app.http.post('city/tiny-station/buy-vip', {
            data: {
                gid: this.data.list[this.data.index].id
            }
        }).then(res => {
            var js = res.data.js
            wx.requestPayment({
                'timeStamp': js.timeStamp,
                'nonceStr': js.nonceStr,
                'package': js.package,
                'signType': js.signType,
                'paySign': js.paySign,
                'success': function(res) {
                    wx.showToast({
                        title: '支付成功！',
                    })
                    setTimeout(() => {
                        wx.navigateBack({

                        })
                    }, 1000)
                },
                fail: err => {
                    app.wxToast.warn("支付失败，请重新支付")
                }
            })
        })
    },
    onShareAppMessage: function() {
        return app.getShareObj('邀请你来逛逛' + wx.getStorageSync('store'))
    }
})